﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Controls
{
    public partial class SortProduct : System.Web.UI.UserControl
    {
        private string url;
        public int sl;
        public static string s;
        public static string sort;
        public static string column;
        protected void Page_Load(object sender, EventArgs e)
        {
         //   flag = 0;

            //ddlSort.SelectedIndex = Convert.ToInt32(selectvalue);
            if (!Page.IsPostBack)
            {
                ddlSort.SelectedIndex = Convert.ToInt32(s);
                string[] listurl = Request.Url.AbsoluteUri.Split('/');
                string url = listurl[listurl.Length - 1];
                if (url == "danhsachsanpham.htm")
                {
                    sl = ListProduct.AllCat;
                }
                if (url == "timkiem.htm")
                {
                    sl = ProductSearch.AllCat;
                }
                if (url == "nhasanxuat.htm")
                {
                    sl = VendorSearch.AllCat;
                }
            }
        
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //flag = 1;
            string link = Request.Url.AbsolutePath;
            string url = Request.Url.Query;
             s = ddlSort.SelectedValue;
             if (s == "1")
             {
                 sort = "DESC";
                 column = "Product_Date";
             }
            if(s=="1")
            {
                sort = "ASC";
                column="newprice";
            }
            if(s=="2")
            {   
                sort = "DESC";
                column = "newprice";
            }
            
            
            url = url.Replace("?", "/");
            url = url.Replace("=", "/");
            url = url.Replace("&", "/");
            url = url.Replace("currentPage", "page");
            
           
            //DataTable dt = new DataTable();
            if (link == "/ListProduct.aspx")
            {
                
                url += "/danhsachsanpham.htm";
            }
            if (link == "/ListBoxProduct.aspx")
            {
              
                url += "/boxsanpham.htm";
            }
            if (link == "/ProductSearch.aspx")
            {
                
                url += "/timkiem.htm";
            }
            if (link == "/VendorSearch.aspx")
            {

                url += "/nhasanxuat.htm";
            }
            Response.Redirect(url);
            
        }
    }
}